Skip to content

RDE-1.20: react-data-export/legacy, the 0.x components on 1.0 (deprecated) - #203

Merged
securedeveloper merged 1 commit into
mainfrom
rde-1.20-legacy
Nov 16, 2026
Merged

securedeveloper merged 1 commit into
mainfrom
rde-1.20-legacy

Conversation

@securedeveloper

Copy link
Copy Markdown
Owner

Summary

RDE-1.20: react-data-export/legacy, a deprecated quick path that runs 0.x code on 1.0 with one import change:

import ReactExport from 'react-data-export/legacy';
const ExcelFile = ReactExport.ExcelFile;
const ExcelSheet = ReactExport.ExcelFile.ExcelSheet;
const ExcelColumn = ReactExport.ExcelFile.ExcelColumn;
  • Exports: ExcelFile, ExcelSheet, ExcelColumn, the 0.x default export (with ExcelFile.ExcelSheet / ExcelFile.ExcelColumn), the 0.x types (ExcelSheetData, ExcelCell, ExcelStyle, …) and convertLegacyStyle. It accepts the dataSet shape (xSteps/ySteps, columns, data) and xlsx-style styles (font.sz, fill.fgColor.rgb, …).
  • A thin layer: sheets come from javascript-excel's fromDataset/fromDatasets. Writing and downloading reuse the 1.0 path (startExport, writeAndSave, the shared export runner, runForTrigger), so StrictMode, abort and CSV behave exactly as in 1.0. No engine logic is duplicated. convertLegacyStyle moves from the migration example into the entry, so there's one implementation; the example now imports it.
  • Deprecated: one development-only warning per page, pointing to docs/migration.md. It's supported for all of 1.x and removed in 2.0. Types and "use client" are included.

Output reproduces 0.6.0, checked against the real 0.6.0

scripts/legacy-goldens.mjs runs react-data-export@0.6.0's own sheet-building code (ExcelFile#createSheetData + excelSheetFromAoA / excelSheetFromDataSet, and its file-name logic, exactly as download() used them before tempa-xlsx) on the scenarios in test/legacy/scenarios.mjs. It writes test/legacy/goldens-0.6.json ("generatedFrom": "react-data-export@0.6.0").

test/legacy/goldens.test.ts exports each scenario through /legacy, reads the file back with javascript-excel/read, and compares every 0.6 cell: position, type, value, date serial and format, and style. It checks that there are no extra cells, compares column widths and the file name, and lists the differences explicitly.

Behaviours reproduced (the docs/migration.md §4 list, each covered):

0.6.0 /legacy tested by
<ExcelColumn> headers plain (not bold) same golden columns-basic, columns-functions, sheets-mixed
dataSet headers bold; a column's style replaces the bold same golden dataset-styles
dataSet object columns { wpx: 80 } unless set; <ExcelColumn> no widths same golden dataset-styles, sheets-mixed
widths applied from column A, the last block with object columns wins same (colProps) golden dataset-blocks
xSteps/ySteps placement (ySteps before the first block too); empty columns: [] takes a header row same (fromDatasets offsets) golden dataset-blocks
dates converted as UTC, built-in format 14 same (dateZone: 'utc') goldens + "writes dates as UTC" (a local-midnight Date gives 0.6's serial)
undefined/NaN → empty text cell, null → no cell, numeric strings stay text same golden columns-basic
default file name Download, extension always appended (report.xlsx → report.xlsx.xlsx); fileExtension: '' takes it from the name same goldens columns-basic, columns-functions, filename-from-name
trigger <span onClick> around element, default <button>Download</button> same markup component test (innerHTML)
data as a function; an empty dataSet falls back to data + columns same goldens columns-functions, sheets-mixed

The tests can fail. I mutation-checked them: bold <ExcelColumn> headers fail 4 scenarios, and 81 px default widths fail 2. The tree-shaking guard (below) fails on a legacy export added to the main entry.

0.6 bugs that stay fixed (deliberate differences)

  • hideElement downloads once under StrictMode, after mount; 0.6 downloaded in the constructor. Tested for xlsx and CSV.
  • fileExtension: 'csv' writes real CSV (UTF-8 BOM, CRLF, injection guard). With several sheets it writes the first one, with a dev warning.
  • 'xls', 'txt', 'html' write an xlsx file with an .xlsx name, plus a dev warning. 0.6 wrote xlsx bytes under the other extension.
  • String dataSet columns (columns: ['Name', 'Dept'], as in the 0.x README) keep their header text. 0.6.0 left them empty: a regression in its last release (commit 855d37a, "if the header has style then the style should be used"); 0.5 wrote the text. This is the one listed difference in the golden test.
  • Falsy <ExcelSheet> / <ExcelColumn> children are skipped (conditionally hide a ExcelColumn from display #155, Unable to Add Condition on <ExcelSheet> for condition base export of sheet tab #160), and an invalid sheet name is sanitized with a dev warning instead of producing a broken file.
  • A { value: Date } cell is written as a date. 0.6 wrote it as text.

Packaging

  • New export ./legacy (import → dist/legacy.js + .d.ts, require → dist/legacy.cjs + .d.cts), and a second tsdown entry. output.exports: 'named' is explicit: CJS gets { default, ExcelFile, … }, which is what bundlers and esModuleInterop expect.
  • Tree-shaken from the main entry. The smoke test follows dist/index.js/.cjs and every chunk they import. It fails if any contains ExcelFile/ExcelSheet/ExcelColumn/xSteps/convertLegacyStyle, or reaches dist/legacy.*. Result: dist/index.js: 2 file(s), no legacy code.
  • "use client" is the first statement of all four entry files (smoke-checked).
  • attw now uses --profile node16: node16 CJS/ESM and bundler, all 🟢 for both entries. node10 (moduleResolution: node) can't resolve any subpath export and isn't a supported mode (TS 5.0+ with node16/nodenext/bundler). The same holds for javascript-excel's subpaths.

Docs

  • docs/migration.md §1.1 "Quick path: react-data-export/legacy", with no renumbering:
    • a type-checked example (examples/migration/legacy-quick-path.tsx)
    • what's reproduced and what's fixed
    • §3.7 now imports convertLegacyStyle
    • §5 notes what /legacy keeps
    • the intro mentions the quick path, and §1's stale "none is out yet" is fixed
  • README: a "Quick path" paragraph in "Migrating from 0.x". The package README gets one line. api.md §2 gets one row.
  • A minor changeset.

Verification (local, Node 26.13.1 via nvm)

  • Clean npm ci; docs:check (11 example blocks match); typecheck (library + playground + docs examples) passes.
  • Tests: 91/91 on React 19, 17 and 18, with 26 new ones: 7 golden + 19 behaviour/style. Playground: 10.
  • Build, publint ("All good!"), attw (node16 profile, all green), and test:release 53/53.
  • Smoke (React 19, 17, 18):
    • directive ok
    • esm ok … export.xlsx
    • dist/index.js: 2 file(s), no legacy code
    • legacy esm ok, legacy cjs ok
    • types ok
  • Consumer TS: 72/72 (TS 5.0.4–7.0.2 × @types/react 18/19 × node16/nodenext/bundler). The fixture uses the 0.x default import, JSX with ExcelFile/ExcelSheet/ExcelColumn/ExcelFile.ExcelSheet, typed ExcelSheetData/LegacyStyle and convertLegacyStyle (.tsx and .cts), plus a probe that <ExcelColumn> requires label.

Regenerating the goldens

mkdir -p /tmp/rde06 && cd /tmp/rde06 && npm init -y >/dev/null
npm install --ignore-scripts react-data-export@0.6.0 react@16.14.0 react-dom@16.14.0 prop-types@15
node scripts/legacy-goldens.mjs --pkg /tmp/rde06

A separate entry with <ExcelFile>, <ExcelSheet>, <ExcelColumn>, the 0.x
default export (ReactExport.ExcelFile.ExcelSheet ...), the dataSet shape
with xSteps/ySteps and xlsx-style styles. It is a thin layer: sheets come
from javascript-excel's fromDataset/fromDatasets, and writing and
downloading go through the 1.0 path (startExport, writeAndSave, the
shared runner), so StrictMode, abort and CSV behave as in 1.0.

Output reproduces 0.6.0: plain <ExcelColumn> headers, bold dataSet
headers replaced by a column style, { wpx: 80 } widths applied from
column A (last block wins), xSteps/ySteps placement, UTC dates with
format 14, 0.6's empty-value rules, "Download" and an always-appended
extension, and the <span> trigger wrapper. Golden tests compare each
scenario cell by cell with what the real react-data-export@0.6.0 built
(scripts/legacy-goldens.mjs). Fixed on purpose: one download under
StrictMode, real CSV for 'csv', xlsx with an .xlsx name and a warning
for xls/txt/html, string dataSet headers keep their text (a 0.6.0
regression), falsy children skipped, invalid sheet names sanitized.

Deprecated: one development warning pointing to docs/migration.md;
supported for all of 1.x, removed in 2.0. convertLegacyStyle moves from
the migration example into the entry. The smoke test checks that the
main entry and its chunks contain no legacy code; attw now checks the
node16 profile (node10 can't resolve subpath exports). Docs: README and
migration.md §1.1 "Quick path", api.md §2. Minor changeset.
@securedeveloper
securedeveloper merged commit 986d0d7 into main Nov 16, 2026
37 checks passed
@securedeveloper
securedeveloper deleted the rde-1.20-legacy branch November 16, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant